<%@ page language="java" contentType="application/vnd.ms-excel; charset=UTF-8"
    pageEncoding="UTF-8" import="com.java.service.*,java.util.*,com.java.model.UserSession,com.java.util.*"%>
<%
	
	//excel 공통으로 받을 인자
	String connGroup 			= CmmUtil.nvl(request.getParameter("connGroup"),"0");
	String user_id 				= CmmUtil.nvl(request.getParameter("user_id"),"");
	String ent_id 				= CmmUtil.nvl(request.getParameter("ent_id"),"");

	//excel 통계타입이 day일 경우 받을 인자
	String start_dt 			= CmmUtil.nvl(request.getParameter("start_dt"),"");
	String close_dt 			= CmmUtil.nvl(request.getParameter("close_dt"),"");

	//excel 통계타입이 month일 경우 받을 인자
	String yyyymm 				= CmmUtil.nvl(request.getParameter("selectYear"),"") 
							+ CmmUtil.nvl(request.getParameter("selectMonth"),"");

	//excel 통계타입이 week일 경우 받을 인자
	String week 				= CmmUtil.nvl(request.getParameter("selectWeek"),"");

	String statistics_type 		= CmmUtil.nvl(request.getParameter("statistics_type"),"");
	
	String daoType 				= "";
	if(statistics_type.equals("day")){ 
		daoType ="Com0301lp02Dao"; //통계타입이 day일 경우
	}else if(statistics_type.equals("week")){
		daoType ="Com0301lp03Dao"; //통계타입이 week일 경우
	}else if(statistics_type.equals("month")){
		daoType ="Com0301lp04Dao"; //통계타입이 month일 경우
	}else if(statistics_type.equals("day_member")){
		daoType ="Com0303lp02Dao"; //통계타입이 day_member 경우
	}else if(statistics_type.equals("week_member")){
		daoType ="Com0303lp03Dao"; //통계타입이 week_member 경우
	}else if(statistics_type.equals("month_member")){
		daoType ="Com0303lp04Dao"; //통계타입이 month_member 경우
	}
	
	HashMap map = new HashMap();
	HashMap map1 = null;
	ArrayList list = new ArrayList();
	CommonDaoService commonservice = new CommonDaoService(daoType);
	map.put("start_dt",start_dt);
	map.put("close_dt",close_dt);
	map.put("yyyymm",yyyymm);
	map.put("week",week);
	map.put("ent_id",ent_id);
	map.put("connGroup",connGroup);
	map.put("user_id",user_id);
	
	list = (ArrayList)commonservice.commonDaoMethod(map);
	
	ArrayList<String> data = new ArrayList<String>();
	ArrayList<String> labels = new ArrayList<String>();
	
	if(list != null){
		if(list.size() > 0){
			map1 = (HashMap)list.get(0);
		}
	}
	
	String data_value ="";
	if(statistics_type.equals("day") || statistics_type.equals("day_member")){
		for(int i=0; i<map1.size(); i++){
			data_value = "h" + String.valueOf(i);
			labels.add(i,String.valueOf(i) + "시");
			data.add(i,CmmUtil.nvl((String)map1.get(data_value),"0"));
		}
	}else if(statistics_type.equals("week") || statistics_type.equals("week_member")){
		String week1[] = {"월","화","수","목","금","토","일"};
		for(int i=0; i<map1.size(); i++){
			data_value = "w" + String.valueOf(i);
			labels.add(i,week1[i]);
			data.add(i,CmmUtil.nvl((String)map1.get(data_value),"0"));
		}
	}else if(statistics_type.equals("month") || statistics_type.equals("month_member")){
		for(int i=0; i<map1.size(); i++){
			data_value = "m" + String.valueOf(i);
			labels.add(i,String.valueOf(i+1));
			data.add(i,CmmUtil.nvl((String)map1.get(data_value),"0"));
		}
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Excel Download</title>
</head>
<body>
<table width="760" border="1" cellpadding="2" cellspacing="0" bordercolor="C0C0C0" bordercolordark="#FFFFFF" frame=below >
	<tr>
		<%for(int i=0; i<labels.size(); i++){ %>
			<td width="55" bgcolor="#D3EBD7" align="center"><%=labels.get(i) %></td>
		<%} %>
	</tr>
	<tr>
		<%for(int i=0; i<data.size(); i++){ %>
			<td width="55" align="center"><%=data.get(i) %></td>
		<%} %>
	</tr>
</table>
</body>
</html>